package com.example.doubanfilm;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.adapter.RecyclerViewAdapterForMain;
import com.example.bean.SpecialZone;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recycleView;
    private TextView search;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 首页返回按钮隐藏
        findViewById(R.id.returnIcon).setVisibility(View.INVISIBLE);

        initData();
    }

    private void initData(){
        search = findViewById(R.id.search);
        recycleView = findViewById(R.id.recyclerView);
        recycleView.setLayoutManager(new LinearLayoutManager(this));
        RecyclerViewAdapterForMain adapter = new RecyclerViewAdapterForMain(R.layout.specialzone_layout, getRecyclerViewData(), this);
        recycleView.setAdapter(adapter);

        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (position){
                    case 0:
                        System.out.println("电影more");
                        break;
                    case 1:
                        System.out.println("电视剧more");
                        break;
                    case 2:
                        System.out.println("综艺more");
                        break;
                }
            }
        });




        // 搜索框点击跳转搜索页面
        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this,SearchActivity.class));
            }
        });
    }



    private List<SpecialZone> getRecyclerViewData(){
        List<SpecialZone> list = new ArrayList<>();
        RecyclerView recyclerViewMovie = new RecyclerView(this);
        RecyclerView recyclerViewTV = new RecyclerView(this);
        RecyclerView recyclerViewVariety = new RecyclerView(this);

        SpecialZone specialZoneMovie = new SpecialZone(getResources().getStringArray(R.array.zoneName)[0],getString(R.string.more),recyclerViewMovie);
        SpecialZone specialZoneTv = new SpecialZone(getResources().getStringArray(R.array.zoneName)[1],getString(R.string.more),recyclerViewTV);
        SpecialZone specialZoneVariety = new SpecialZone(getResources().getStringArray(R.array.zoneName)[2],getString(R.string.more),recyclerViewVariety);

        list.add(specialZoneMovie);
        list.add(specialZoneTv);
        list.add(specialZoneVariety);
        return list;
    }

}